
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tama_Chan.GameEngine_ns;


namespace Tama_Chan.FontParticleEngine_ns
{
   public class FontParticleEngine
   {
      private GameEngine GameEngine { get; set; }
      private const long LifeTime = 20000000L;
      public IList<FontParticle> FontParticles { get; set; }
      private Vector2 Velocity { get; set; }
      public SpriteFont FloatingMessageFont { get; set; }


      public FontParticleEngine(GameEngine gameEngine)
      {
         GameEngine = gameEngine;
         FontParticles = new List<FontParticle>();
         Velocity = new Vector2(0f, -2.5f);
      }


      public void Initialize()
      {
         // ...
      }


      public void LoadContent()
      {
         FloatingMessageFont = GameEngine.Game1.Content.Load<SpriteFont>(@"Fonts\FloatingMessageFont");
      }


      public void Update(GameTime gameTime)
      {
         for(int i=0; i<FontParticles.Count; i++)
         {
            FontParticle fontParticle = FontParticles[i];

            if(gameTime.TotalGameTime.Ticks - fontParticle.BirthTime > LifeTime ||
               fontParticle.Position.Y <= GameEngine.Game1.GameBounds.Y)
            {
               FontParticles.Remove(fontParticle);
               continue;
            }

            fontParticle.Position += Velocity;
         }
      }


      public void Draw()
      {
         for(int i=0; i<FontParticles.Count; i++)
         {
            FontParticle fontParticle = FontParticles[i];
            GameEngine.Game1.SpriteBatch.DrawString( GameEngine.ScoreFont, 
                                                     fontParticle.Text, 
                                                     fontParticle.Position, 
                                                     fontParticle.Color, 
                                                     0f, 
                                                     Vector2.Zero,
                                                     Vector2.One,
                                                     SpriteEffects.None, 
                                                     GameEngine.FontParticleDepth);
         }
      }


      public void AddFontParticle(Vector2 position, string text, Color color, long birthTime)
      {
         FontParticles.Add(new FontParticle(position, text, color, birthTime));
      }

   }
}
